package com.yc.vote.controller;

import com.yc.vote.entity.User;
import com.yc.vote.mapper.UserMapper;
import com.yc.vote.vo.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 投票系统-用户表-4 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/vote/user")
public class UserController {


    @Resource
    UserMapper userMapper;

    @GetMapping("getUser")
    public Result getUser(HttpSession session){
        User user = (User) session.getAttribute("loginedUser");
        Integer id = user.getId();

        user = userMapper.selectById(id);

        return new Result(1,"",user);
    }


    @GetMapping ("isOne")
    public Result result(HttpSession session,Integer usid){
        User user = (User) session.getAttribute("loginedUser");
        if (user.getId() != usid){
            return new Result(0,"仅可以修改你自己发布的投票",null);
        }
        return new Result(1,"",null);
    }

}
